using Kassandra.Core;
using Kassandra.WindowsUI;
using NUnit.Framework;
using Rhino.Mocks;

namespace Kassandra.Tests.WindowsUI
{
    public class ImageExistanceTests
    {
        [TestFixture]
        public class When_checking_for_a_character
        {
            private MockRepository _mockery;
            private ICheckForExistingImageByAssignedCharacter _checkForExistingImageByAssignedCharacter;
            private ICharacterToFileNameTranslator _mockCharacterToFileNameTranslator;
            private IImageFileFinder _mockImageFileFinder;

            [SetUp]
            public void Setup()
            {
                _mockery = new MockRepository();
                _mockCharacterToFileNameTranslator = _mockery.DynamicMock<ICharacterToFileNameTranslator>();
                _mockImageFileFinder = _mockery.DynamicMock<IImageFileFinder>();
                _checkForExistingImageByAssignedCharacter =
                    new CheckForExistingImageByAssignedCharacter(_mockCharacterToFileNameTranslator,
                                                                 _mockImageFileFinder);
            }

            [Test]
            public void the_file_system_should_be_checked_for_an_image_with_the_translated_file_name()
            {
                using (_mockery.Record())
                {
                    Expect.Call(_mockImageFileFinder.FileExistsWithNameOf(string.Empty)).IgnoreArguments().Return(null).
                        Repeat.Once();
                }

                using (_mockery.Playback())
                {
                    _checkForExistingImageByAssignedCharacter.AgainstTheCharacter('c');
                }
            }

            [Test]
            public void the_character_should_be_translated_into_a_filename()
            {
                using (_mockery.Record())
                {
                    Expect.Call(_mockCharacterToFileNameTranslator.Using('c')).IgnoreArguments().Return(string.Empty).
                        Repeat.Once();
                }

                using (_mockery.Playback())
                {
                    _checkForExistingImageByAssignedCharacter.AgainstTheCharacter('c');
                }
            }
        }
    }
}